package com.liulin.cdse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liulin.cdse.entity.Manager;
import com.liulin.cdse.entity.Supplier;
import com.liulin.cdse.exception.AccountExistException;
import com.liulin.cdse.mapper.ManagerMapper;
import com.liulin.cdse.mapper.SupplierMapper;
import com.liulin.cdse.service.ManagerService;
import com.liulin.cdse.service.SupplierService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName SupplierServiceImpl
 * @Project cdse
 * @Package_name com.liulin.cdse.service.impl
 * @Description todo
 * @Author 1354414
 * @Data 2025/5/20
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public void add(Supplier supplier) {
        //判断管理员账号是否已经存在
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", supplier.getName());

        Long count = supplierMapper.selectCount(queryWrapper);
        //如果存在，抛出异常
        if (count > 0) {
            throw new AccountExistException("供应商" + supplier.getName() + "已存在");
        }

        //如果不存在，直接增加到表中
        supplierMapper.insert(supplier);
    }
}
